package com.senken.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.senken.mapper.ReuturnsMapper;
import com.senken.commons.entity.FidStateAndPage;
import com.senken.entity.Reuturns;
import com.senken.service.IApproveService;
import com.senken.service.IReuturnsService;
import com.senken.service.ISkWoService;
import com.senken.service.ITotalstateService;
import com.senken.util.CreateWo;
import com.baomidou.framework.service.impl.SuperServiceImpl;

/**
 *
 * Reuturns 表数据服务层接口实现类
 *
 */
@Service
public class ReuturnsServiceImpl extends SuperServiceImpl<ReuturnsMapper, Reuturns> implements IReuturnsService {

	private static final int NUM=10;
	@Autowired
	private ReuturnsMapper reuturnsMapper;
	@Autowired
	private ISkWoService service;
	@Autowired
	private IApproveService approveService;
	@Autowired
	private ITotalstateService totalService;
	
	@Override
	public List<Reuturns> selectReuturns(){
		return reuturnsMapper.selectReturnsOrderBytime();
	}
	
	@Override
	public List<Reuturns> selectReturnByState(int state,int page){
		FidStateAndPage fidStateAndPage = new FidStateAndPage();
		fidStateAndPage.setState(state);
		fidStateAndPage.setNum(NUM);
		fidStateAndPage.setStart((page-1)*NUM);
		return reuturnsMapper.selectReturnBystate(fidStateAndPage);
	}
	
	@Override
	public Reuturns selectreturn(int hid){
		Reuturns reuturns = new Reuturns();
		reuturns.setHid(hid);
		return this.selectOne(reuturns);
	}
	
	@Override
	public int add(String customer,String phone,int roleid){
		Reuturns reuturns = new Reuturns();
		reuturns.setCustomer(customer);
		reuturns.setPhone(phone);
		reuturns.setStartime(new Date());
		reuturns.setWo(CreateWo.Createwo(service));
		this.insert(reuturns);
		approveService.addapprove(reuturns.getHid(), roleid);
		totalService.add(reuturns.getHid(),4);
		return reuturns.getHid();
	}

}